<?php
header( "Content-Type:text/html; charset=utf-8" );
require_once("config.inc.php");
require_once("db.class.php");
set_time_limit(0);

$table = "20";

echo "*** insert century{$table} start.***<br/>\n";

$db = new db($site_Db);

$results = $db->fetchrows("SELECT * FROM cal{$table}");
if( !empty($results) )
{
	foreach ($results as $result) {
		/*
		$info_array = array();
		$cdate = trim($result['cdate']);
		$cinfo = trim($result['cinfo']);
		preg_match("/^(.+?)\r(.+?)\r(.+?)\r(.+?)\r(.+?)\r(.+?)\r(.+?)\r(.+?)$/u", $cinfo, $match);
		*/
		$info_array = unserialize($result['cinfo']);
		$sql = "REPLACE INTO century{$table} VALUES('".$result['cdate']."','".$info_array['星期']."','".$info_array['星座']."','".$info_array['节日']."','".$info_array['农历']."','".$info_array['节气']."','".$info_array['干支']."','".$info_array['二十八宿']."','".$info_array['甲子纳音']."')";
		//echo $sql;exit();
		
		/*
		$info_array['星期'] = trim($match[1]);
		$info_array['星座'] = str_replace('星座:','',trim($match[2]));
		$info_array['节日'] = str_replace('节日:','',trim($match[3]));
		$info_array['农历'] = str_replace('农历:','',trim($match[4]));
		$info_array['节气'] = trim($match[5]);
		$info_array['干支'] = str_replace('干支:','',trim($match[6]));
		$info_array['二十八宿'] = str_replace('二十八宿:','',trim($match[7]));
		$info_array['甲子纳音'] = str_replace('甲子纳音:','',trim($match[8]));
		
		$newcinfo = serialize($info_array);
		
		$mdate = trim($result['mdate']);
		$mnl = str_replace('　','',trim($result['mnl']));
		*/
		//echo "UPDATE {$table} SET mnl='{$mnl}' WHERE mdate='{$mdate}'";
		if($db->query($sql))
			echo "Update {$result['cdate']} successful.\n";
		
	}
	
} else {
	echo "No data.\n";
}

$db->close();

?>